﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【状态标准】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto状态标准
    /// </summary>
    public abstract class AutoStandStatusMapping : BaseMapping<StandStatus, StandStatusModel, StandStatusFilterModel>
    {
        public AutoStandStatusMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override StandStatusModel Entity2Model(StandStatus entity)
        {
            StandStatusModel model = new StandStatusModel();

            model.StandStatusID = entity.StandStatusID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Name = entity.Name;
            model.Type = entity.Type;
            model.Remark = entity.Remark;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override StandStatus Model2Entity(StandStatusModel model)
        {
            StandStatus entity = new StandStatus();

            entity.StandStatusID = model.StandStatusID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Name = model.Name;
            entity.Type = model.Type;
            entity.Remark = model.Remark;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<StandStatus> FilterModel2Where(StandStatusFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._StandStatusID.HasValue)
            {
                where = where.And(x => x.StandStatusID == filterModel._StandStatusID.Value);
            }
            if (filterModel._StandStatusIDs.IsNotEmpty() && filterModel._StandStatusIDs.Count > 0)
            {
                where = where.And(x => filterModel._StandStatusIDs.Contains(x.StandStatusID));
            }
            if (filterModel._NotStandStatusIDs.IsNotEmpty() && filterModel._NotStandStatusIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotStandStatusIDs.Contains(x.StandStatusID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //名称
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            //类型
            if (filterModel._Type.HasValue)
            {
                where = where.And(x => x.Type == filterModel._Type.Value);
            }
            if (filterModel._Types.IsNotEmpty() && filterModel._Types.Count > 0)
            {
                where = where.And(x => filterModel._Types.Contains(x.Type));
            }
            if (filterModel._NotTypes.IsNotEmpty() && filterModel._NotTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotTypes.Contains(x.Type));
            }

            return where;
        }
        #endregion
    }
}

